#include <iostream>
#include <map>

int max = 0, min = 1 << 30;

int main()
{
	int n;
	while (std::cin >> n) {
		std::map<int, int> mm;
		max = 0; min = 1 << 30;
		for (int i = 0; i < n; i++) {
			int x;
			std::cin >> x;
			mm[x]++;
			if (mm[x] > max) {
				max = mm[x];
				min = x;
			} else if (mm[x] == max) {
				if (x < min) {
					min = x;
				}
			}
		}
		std::cout << min << "\n";
	}
}

